//
// Created by choumei on 2021/9/11.
//

#include "MyDevice.h"
#include<QDebug>
#include<random>
#include<QFile>
#include <QTime>

qint64 MyDevice::readData(char *data, qint64 maxlen) {
    struct MsgInfo {
        int32_t msgSize;
        int32_t msgType;
        int32_t msgId;
    };
    MsgInfo info;
    buffer->read((char *) &info.msgSize, 4);
    buffer->read((char *) &info.msgType, 4);
    buffer->read((char *) &info.msgId, 4);
    buffer->read(data, info.msgSize);
    qDebug() << info.msgSize;
    return info.msgSize;
}

qint64 MyDevice::writeData(const char *data, qint64 len) {
//    int len2 = f2.write(data, len);
//    qDebug() << len2;
    qDebug() << len;
    return 0;
}

MyDevice::MyDevice(MyBuffer *buffer) {
    this->buffer = buffer;
    this->open(QIODevice::ReadWrite);
    f.setFileName("/home/choumei/CLionProjects/NetClient/resource/audio.pcm");
    f.open(ReadOnly);
    f2.setFileName("/home/choumei/CLionProjects/NetClient/resource/audio2.pcm");
    f2.open(QIODevice::ReadWrite);
    array = f.readAll();
}

//MyDevice::QIODevice() {
//    this->open(QIODevice::ReadOnly);
//}

